package com.ruoyi.forum.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.forum.domain.ForumCurrentEvent;
import com.ruoyi.forum.service.IForumCurrentEventService;
import com.ruoyi.forum.utils.SocialistCoreCheck;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 时事-（用于给学校发布事件所用，可实时向学生展示当前学校所发送的事情。）Controller
 * 
 * @author ruoyi
 * @date 2024-02-09
 */
@Api(tags="论坛-时事管理")
@RestController
@RequestMapping("/forum/event")
public class ForumCurrentEventController extends BaseController
{
    @Autowired
    private IForumCurrentEventService forumCurrentEventService;

    @Autowired
    private SocialistCoreCheck socialistCoreCheck;

    /**
     * 查询时事-分页列表查询
     */
    @ApiOperation(value="查询时事", notes="论坛-时事管理-分页列表查询")
    @PreAuthorize("@ss.hasPermi('forum:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumCurrentEvent forumCurrentEvent)
    {
        startPage();
        if(forumCurrentEvent.getDelFlag()==null){
            forumCurrentEvent.setDelFlag("0");
        }
        List<ForumCurrentEvent> list = forumCurrentEventService.selectForumCurrentEventList(forumCurrentEvent);
        return getDataTable(list);
    }

    /**
     * 导出时事-导出时事管理列表
     */
    @ApiOperation(value="导出时事", notes="论坛-时事管理-导出时事管理列表")
    @PreAuthorize("@ss.hasPermi('forum:event:export')")
    @Log(title = "导出时事", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumCurrentEvent forumCurrentEvent)
    {
        List<ForumCurrentEvent> list = forumCurrentEventService.selectForumCurrentEventList(forumCurrentEvent);
        ExcelUtil<ForumCurrentEvent> util = new ExcelUtil<ForumCurrentEvent>(ForumCurrentEvent.class);
        util.exportExcel(response, list, "时事-（用于给学校发布事件所用，可实时向学生展示当前学校所发送的事情。）数据");
    }

    /**
     * 获取时事-详细信息
     */
    @ApiOperation(value="获取时事", notes="论坛-时事管理-详细信息")
    @PreAuthorize("@ss.hasPermi('forum:event:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(forumCurrentEventService.selectForumCurrentEventById(id));
    }

    /**
     * 新增时事
     */
    @ApiOperation(value="新增时事", notes="论坛-时事管理-新增时事")
    @PreAuthorize("@ss.hasPermi('forum:event:add')")
    @Log(title = "时事-（用于给学校发布事件所用，可实时向学生展示当前学校所发送的事情。）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumCurrentEvent forumCurrentEvent)
    {
        boolean check = socialistCoreCheck.checkContent(forumCurrentEvent.getContent());
        if (!check){
            return new AjaxResult(HttpStatus.check,"发布内容有问题，请重新编辑更改，要符合社会主义核心价值观！");
        }
        forumCurrentEvent.setCreateBy(getUsername());
        return toAjax(forumCurrentEventService.insertForumCurrentEvent(forumCurrentEvent));
    }

    /**
     * 修改时事
     */
    @ApiOperation(value="修改时事", notes="论坛-时事管理-修改时事")
    @PreAuthorize("@ss.hasPermi('forum:event:edit')")
    @Log(title = "时事-（用于给学校发布事件所用，可实时向学生展示当前学校所发送的事情。）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumCurrentEvent forumCurrentEvent)
    {
        forumCurrentEvent.setUpdateBy(getUsername());
        return toAjax(forumCurrentEventService.updateForumCurrentEvent(forumCurrentEvent));
    }

    /**
     * 删除时事
     */
    @ApiOperation(value="删除时事", notes="论坛-时事管理-删除时事")
    @PreAuthorize("@ss.hasPermi('forum:event:remove')")
    @Log(title = "时事-（用于给学校发布事件所用，可实时向学生展示当前学校所发送的事情。）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(forumCurrentEventService.deleteForumCurrentEventByIds(ids));
    }

}
